// Unit test for the model::attributeInfo class
// Copyright 2004 (C) Ralph Thomas

#include <model/attributeInfo.h>
#include <model/attributeNames.h>
#include <tests/testCore.h>

namespace model {
	class testAttributeInfo : public test::basic {
	  public:
		const char* performTest() {
			attributeInfo ai;

			if( ai.getNumberAttributes() != 0 )
				return "empty attributeInfo reports attributes";
			ai.addAttribute( "26", false );
			if( ai.getNumberAttributes() != 1 )
				return "attributeInfo doesn't report one attribute";
			ai.addAttribute( "26", true );
			if( ai.getNumberAttributes() != 1 )
				return "attributeInfo didn't check to see if it already had an attribute";
			if( ai.getName( 0 ) != "26" )
				return "attributeInfo recorded incorrect name";
			if( ai.getSettable( 0 ) != true )
				return "attributeInfo didn't update settable property";
			ai.addAttribute( "27", false );
			if( ai.getNumberAttributes() != 2 )
				return "attributeInfo didn't report two attributes";
			if( ai.getName( 1 ) != "27" )
				return "attributeInfo misrecorded second name";
			if( ai.getSettable( 1 ) != false )
				return "attributeInfo misrecorded second settable property";
			attributeInfo ai2( ai );
			if( ai2.getNumberAttributes() != 2 )
				return "copied attributeInfo misreported number of attributes";
			if( ai2.getName( 0 ) != "26" )
				return "copied attributeInfo misreported first attribute's name";
			if( ai2.getSettable( 0 ) != true )
				return "copied attributeInfo misreported first attribute's settable property";
			if( ai2.getName( 1 ) != "27" )
				return "copied attributeInfo misreported second attribute's name";
			if( ai2.getSettable( 1 ) != false )
				return "copied attributeInfo misreported second attribute's settable property";

			attributeInfo ai3 = ai2;
			if( ai3.getNumberAttributes() != 2 )
				return "copied attributeInfo misreported number of attributes";
			if( ai3.getName( 0 ) != "26" )
				return "copied attributeInfo misreported first attribute's name";
			if( ai3.getSettable( 0 ) != true )
				return "copied attributeInfo misreported first attribute's settable property";
			if( ai3.getName( 1 ) != "27" )
				return "copied attributeInfo misreported second attribute's name";
			if( ai3.getSettable( 1 ) != false )
				return "copied attributeInfo misreported second attribute's settable property";

			return 0;
		}
		const char* getTestName() {
			return "test basic properties of model::attributeInfo";
		}
	};
};

void test::runnerSingleton::registerTests() {
	adoptTest( new model::testAttributeInfo() );
}
